import json

filename = "favorite_number.json"
try:
    with open(filename) as file_object:
        favorite_number = json.load(file_object)
        print(f"I know your favorite number! It’s {favorite_number}.")
except FileNotFoundError:
    favorite_number = input("请输入你喜欢的数字：")
    try:
        with open(filename, 'w') as file_object:
            json.dump(int(favorite_number), file_object)
    except ValueError:
        print("你输入的不是有效的数字哦，请重新输入。")